<?php get_instance()->view('common/header');?>
<body>
<style>
    .weui-badge{position: absolute;top: -.4em;right: 0.1em;}
</style>
<div class="tabcard">
    <a href="<?php echo getUrl('order/orderList?type=1&page=1')?>" <?php if($type == 1):?> class="actived" <?php endif;?>>送货上门</a>
    <a href="<?php echo getUrl('order/orderList?type=2&page=1')?>" <?php if($type == 2):?> class="actived" <?php endif;?>>到店自提</a>
</div>

<div class="tabcardcons mt10">
    <div class="tabcontent actived">
        <div class="saixuan">
            <a  href="<?php echo getUrl('order/orderList?type='.$type.'&status=0')?>" class="actived">全部</a>
            <?php if($type == 1):?>
                <a attr="1-1" href="<?php echo getUrl('order/orderList?type=1&status=1')?>">待支付<?php if($number['delPayNumber']):?><span class="weui-badge" ><?php echo $number['delPayNumber']?></span><?php endif;?></a>
                <a attr="1-2" href="<?php echo getUrl('order/orderList?type=1&status=2')?>">备货中<?php if($number['delAcceptNumber']):?><span class="weui-badge" ><?php echo $number['delAcceptNumber']?></span><?php endif;?></a>
                <a attr="1-3" href="<?php echo getUrl('order/orderList?type=1&status=3')?>">配送中<?php if($number['delShipNumber']):?><span class="weui-badge" ><?php echo $number['delShipNumber']?></span><?php endif;?></a>
                <a attr="1-4" href="<?php echo getUrl('order/orderList?type=1&status=4')?>">待评价<?php if($number['delCommentNumber']):?><span class="weui-badge" ><?php echo $number['delCommentNumber']?></span><?php endif;?></a>
            <?php else:?>
                <a attr="2-1" href="<?php echo getUrl('order/orderList?type=2&status=1')?>">待支付<?php if($number['storePayNumber']):?><span class="weui-badge" ><?php echo $number['storePayNumber']?></span><?php endif;?></a>
                <a attr="2-3" href="<?php echo getUrl('order/orderList?type=2&status=3')?>">待核销<?php if($number['storeCheckNumber']):?><span class="weui-badge" ><?php echo $number['storeCheckNumber']?></span><?php endif;?></a>
                <a attr="2-4" href="<?php echo getUrl('order/orderList?type=2&status=4')?>">待评价<?php if($number['storeCommentNumber']):?><span class="weui-badge" ><?php echo $number['storeCommentNumber']?></span><?php endif;?></a>
                <a attr="2-5" href="<?php echo getUrl('order/orderList?type=2&status=5')?>">已完成</a>
            <?php endif;?>
            <div class="after"></div>
        </div>
        <?php if($list):?>
            <div class="weui-panel__bd list">
                <?php foreach ($list as $key=>$v):?>
                    <div class="p10 bor_bb orderid<?php echo $v['id']?>">
                        <a href="<?php echo getUrl('order/orderDetail?order_id='.$v['id'])?>" class="weui-media-box_appmsg afterbor100 mb10">
                            <div class="weui-media-box__hd" style="width: 4em; height: 4em;">
                                <img class="weui-media-box__thumb" src="<?php echo $v['portrait']?>" alt="">
                            </div>
                            <div class="weui-media-box__bd">
                                <h4 class="weui-media-box__title lh10 textEll f09"><?php echo $v['shop_name'];?></h4>
                                <p class="f07 cor9"><?php echo $v['addtime'];?></p>
                                <p class="weui-media-box__desc textEll mt5"><?php echo $v['title'];?></p>
                            </div>
                            <div class="">
                                <p class="f08 mb10 orderstatus<?php echo $v['id']?>"><?php echo $v['status_desc'];?></p>
                                <p class="f11">¥<?php echo $v['reality_amount'];?></p>
                            </div>
                        </a>
                        <?php if($v['status'] == 1):?>
                            <!-- 待支付-->
                            <div class="heng vCenter">
                                <p class="cor9 f07">付款剩余时间<span class="f10 ml5 timespan<?php echo $v['id'];?>"><b class="f11"></b>小时<b class="f11"></b>分钟</span></p>
                                <div>
                                    <a alert-message="确定是否取消订单？" href="<?php echo getUrl("order/orderCancel?order_id=".$v['id'])?>" class="ajax-request-btn weui-btn_mini borbtn widbtn cbtn">取消订单</a>
                                    <a href="<?php echo getUrl('product/orderPay?code='.$v['code'])?>" class="weui-btn_mini borbtn widbtn hbtn">立即支付</a>
                                </div>
                            </div>
                        <?php elseif ($v['status'] == 2):?>
                            <!-- 待接单-->
                            <div class="hengright">
                                <div>
                                    <a  alert-message="确定是否立即提醒商家接单？" href="<?php echo getUrl('order/push?order_id='.$v['id'])?>" class="ajax-request-btn weui-btn_mini borbtn widbtn hbtn">催一下</a>
                                    <a alert-message="确定是否取消订单？" href="<?php echo getUrl("order/orderCancel?order_id=".$v['id'])?>" class="ajax-request-btn weui-btn_mini borbtn widbtn cbtn">取消订单</a>
                                </div>
                            </div>

                        <?php elseif ($v['status'] == 4 ):?>
                            <!-- 待评价-->
                            <div class="hengright">
                                <div>
<!--                                    <a href="--><?php //echo getUrl('order/saveService?order_id='.$v['id'])?><!--" class="weui-btn_mini borbtn widbtn cbtn">申请售后</a>-->
                                    <a href="<?php echo getUrl('order/saveComment?order_id='.$v['id'])?>" class="weui-btn_mini borbtn widbtn hbtn">立即评价</a>
                                </div>
                            </div>
                        <?php elseif ($v['status'] == 5):?>
                            <!-- 已完成-->
                            <div class="hengright">
                                <div>
                                    <a alert-message="确定是否删除订单？" href="<?php echo getUrl("order/orderRemove?order_id=".$v['id'])?>" class="ajax-request-btn weui-btn_mini borbtn widbtn nbtn">删除订单</a>
                                    <a href="<?php echo getUrl('product/merchant?merchant_id='.$v['merchant_id'])?>" class="weui-btn_mini borbtn widbtn hbtn">再次消费</a>
                                </div>
                            </div>
                        <?php elseif ($v['status'] == 7):?>
                            <!-- 已完成-->
                            <div class="hengright">
                                <div>
                                    <a alert-message="确定是否删除订单？" href="<?php echo getUrl("order/orderRemove?order_id=".$v['id'])?>" class="ajax-request-btn weui-btn_mini borbtn widbtn nbtn">删除订单</a>
                                </div>
                            </div>
                        <?php endif;?>
                    </div>
                <?php endforeach;?>
            </div>
            <div class="weui-loadmore" style="display: none">
                <div class="load">
                    <i class="weui-loading"></i>
                    <span class="weui-loadmore__tips">正在加载</span>
                </div>
                <span class="noC" style="display: none">没有更多内容了~</span>
            </div>
        <?php else:?>
            <div class="statebox chuizhi jdjz" style="flex: 1;height: 100%;">
                <img class="stateimgda mb5" src="<?php echo $this->staticUrl?>img/default/5.png" alt="">
                <span class="f09 cor9 tc mb20">你还没有订单哦！</span>
            </div>
        <?php endif;?>
    </div>
    <div class="tabcontent"></div>
</div>
<?php get_instance()->view('common/footer');?>
</body>
<script src="<?php echo $this->staticUrl?>js/jquery-weui.js"></script>
<script type="text/javascript">
    $(function () {
        /**
         * 上拉加载数据
         */
        var page = 1,
            type = "<?php echo $type?>",
            status = "<?php echo $status?>";

        var loading = false;  //状态标记
        $(document.body).infinite().on("infinite", function() {
            if(loading) return;
            loading = true;
            $(".weui-loadmore").show();
            $(".load").show();
            $(".noC").hide();
            var dUrl = "<?php echo getUrl('order/orderDetail?order_id=')?>",
                sUrl = "<?php echo getUrl('order/saveService?order_id=')?>",
                cUrl = "<?php echo getUrl('order/saveComment?order_id=')?>";
                delUrl = "<?php echo getUrl('order/orderRemove?order_id=')?>",
                cancleUrl = "<?php echo getUrl('order/orderCancel?order_id=')?>",
                    storeUrl = "getUrl('product/merchant?merchant_id=')",
                pUrl = "<?php echo getUrl('order/push?order_id=')?>";

            $.ajax('<?php echo getUrl('order/getOrderList');?>', {
                type:'post',
                data:{page:page,type:type,status:status},
                dataType:'json',
                error:function(){
                    show_message({status:0, message:'请求超时'});
                },
                timeout:60000,
                success:function(e){
                    loading = false;
                    if (e.status == 0){
                        show_message(e);
                        return;
                    }

                    if (!e.data.length){
                        $(document.body).destroyInfinite();
                        $(".load").hide();
                        $(".noC").show();
                        return;
                    }
                    page += 1;
                    $(".weui-loadmore").hide();
                    var html;
                    $.each(e.data, function (key, obj) {
                        var divHtml = '';
                        if (obj.status == 1){ <!-- 待支付-->
                            divHtml =
                                '<div class="heng vCenter">' +
                                '   <p class="cor9 f07">付款剩余时间<span class="f10 ml5 timespan'+obj.id+'" id="timer"><b class="f11">12</b>小时<b class="f11">57</b>分钟</span></p>' +
                                '   <div>' +
                                '       <a alert-message="确定是否取消订单？" href="'+cancleUrl+obj.id+'" class="ajax-request-btn weui-btn_mini borbtn widbtn cbtn">取消订单</a>' +
                                '       <a href="" class="weui-btn_mini borbtn widbtn hbtn">立即支付</a>' +
                                '   </div>' +
                                '</div>';
                        }else if(obj.status == 2){ <!-- 待接单-->
                            divHtml =
                                '<div class="hengright">' +
                                '   <div>' +
                                '       <a alert-message="确定是否立即提醒商家接单？"  href="'+pUrl+obj.id+'" class="ajax-request-btn weui-btn_mini borbtn widbtn hbtn">催一下</a>' +
                                '<a alert-message="确定是否取消订单？" href="'+cancleUrl+obj.id+'" class="ajax-request-btn weui-btn_mini borbtn widbtn cbtn">取消订单</a>' +
                                '   </div>' +
                                '</div>';

                        }else if(obj.status == 4 ){ <!-- 配送中-->
                            divHtml =
                                '<div class="hengright">' +
                                '   <div>' +
//                                '       <a href="'+sUrl+obj.id+'" class="weui-btn_mini borbtn widbtn cbtn">申请售后</a>' +
                                '       <a href="'+cUrl+obj.id+'" class="weui-btn_mini borbtn widbtn hbtn">立即评价</a>' +
                                '   </div>' +
                                '</div>';
                        }else if(obj.status == 5){ <!-- 已完成-->
                            divHtml =
                                '<div class="hengright">' +
                                '   <div>' +
                                '       <a href="'+delUrl+obj.id+'" alert-message="确定是否删除订单？" class="ajax-request-btn weui-btn_mini borbtn widbtn nbtn">删除订单</a>' +
                                '       <a href="'+storeUrl+obj.merchant_id+'" class="weui-btn_mini borbtn widbtn hbtn">再次消费</a>' +
                                '   </div>' +
                                '</div>';
                        }else if(obj.status == 7){ <!-- 已完成-->
                            divHtml =
                                '<div class="hengright">' +
                                '   <div>' +
                                '       <a href="'+delUrl+obj.id+'" alert-message="确定是否删除订单？" class="ajax-request-btn weui-btn_mini borbtn widbtn nbtn">删除订单</a>' +
                                '   </div>' +
                                '</div>';
                        }
                        html =
                            '<div class="p10 bor_bb orderid'+obj.id+'">' +
                            '   <a href="'+dUrl+obj.id+'" class="weui-media-box_appmsg afterbor100 mb10">' +
                            '       <div class="weui-media-box__hd" style="width: 4em; height: 4em;">' +
                            '           <img class="weui-media-box__thumb" src="'+obj.portrait+'" alt="">' +
                            '       </div>' +
                            '       <div class="weui-media-box__bd">' +
                            '           <h4 class="weui-media-box__title lh10 textEll f09">'+obj.shop_name+'</h4>' +
                            '           <p class="f07 cor9">'+obj.addtime+'</p>' +
                            '           <p class="weui-media-box__desc textEll mt5">'+obj.title+'</p>' +
                            '       </div>' +
                            '       <div class="">' +
                            '           <p class="f08 mb10 orderstatus'+obj.id+'">'+obj.status_desc+'</p>' +
                            '           <p class="f11">¥'+obj.reality_amount+'</p>' +
                            '       </div>' +
                            '   </a>' + divHtml +
                            '</div>';
                        $(".list").append(html);
                    });
                }
            });
        });
    });
</script>
<script type="text/javascript">
    function daojishi(obj) {
        setInterval(function () {
            var addTime = obj.addtime;
            var dateTime =new Date(Date.parse(addTime.replace(/-/g,"/")));//下单时间
            var leftTime =  new Date().getTime() -  dateTime.getTime();
            leftTime = 30*60*1000  - leftTime;
            var minute =parseInt(leftTime/1000/60%60,10);
            var second = parseInt(leftTime/1000%60,10);
            var min = checkTime(minute);
            var sec = checkTime(second);
            $(".timespan"+obj.order_id).html('<b class="f11">'+min+'</b>分<b class="f11">'+sec+'</b>秒');
        }, 1000);
    }
	function checkTime(i){
		if(i < 10 ){
			i = "0" + i;
		}
		return i;
	}
    $(function () {
        var addTimes = '<?php echo $addtimes;?>';

        var type = <?php echo $type?>;
        var status = <?php echo $status?>;
        $(".saixuan>a").each(function(){
            if($(this).attr('attr') == type+'-'+status){
                $(this).addClass('actived').siblings().removeClass('actived');
            }
        });
        //倒计时
        $.each($.parseJSON(addTimes),function (key,val) {
            daojishi(val);
        });
        //删除订单
        $(".list").delegate('.orderRemove', 'touchstart', function () {
//        $('.orderRemove').click(function () {
            var orderid = $(this).attr('orderid');
            $.ajax({
                url: '<?php echo getUrl("order/orderRemove")?>',
                type:"POST",
                data:{
                    order_id:orderid
                },
                success:function(arr){
                    show_message({status:arr.status, message:arr.message});
                    if(arr.status == "1"){
                        $(document).find('.orderid'+orderid).remove();
                    }
                    return false;
                },
                dataType:'json'
            });
        });
        //取消订单
        $(".list").delegate('.orderCancel', 'touchstart', function () {
//        $('.orderCancel').click(function () {
            var orderid = $(this).attr('orderid');

            $.ajax({
                url: '<?php echo getUrl("order/orderCancel")?>',
                type:"POST",
                data:{
                    order_id:orderid
                },
                success:function(arr){
                    show_message({status:arr.status, message:arr.message});
                    if(arr.status == "1"){
                        var div = $('.weui-panel__bd').find('[orderid='+orderid+']').parent();
                        div.html('<a href="javascript:;" orderid="'+orderid+'" class="orderRemove weui-btn_mini borbtn widbtn nbtn">删除订单</a>');
                        $('.weui-panel__bd').find('.orderstatus'+orderid).text('交易关闭');//改变订单状态
                        div.prev().text('');//去掉倒计时提示
                    }
                    return false;
                },
                dataType:'json'
            });
        });
        //催一下
        $(".list").delegate('.push', 'touchstart', function () {
//        $('.push').click(function () {
            var orderid = $(this).attr('orderid');
            $.ajax({
                url: '<?php echo getUrl("order/push")?>',
                type:"POST",
                data:{
                    order_id:orderid
                },
                success:function(arr){
                    show_message({status:arr.status, message:arr.message});
                    return false;
                },
                dataType:'json'
            });
        });

        $.e_validate.init('.weui-panel__bd',{saveMessage:'提交中...'});
    })

</script>
<script src="<?php echo $this->staticUrl?>js/base.js"></script>
</html>
